//定义store
import { defineStore } from "pinia";
import {ref} from 'vue'

export const useTokenStore = defineStore('token',()=>{
    //定义状态的内容

    //1.响应式变量
    const token = ref()
    const studentInfo = ref({})

    //2.定义一个函数，修改token的值
    const setToken = (newToken, student) => {
        token.value = newToken
        studentInfo.value = student
    }
    //用户信息 
    const setStudentInfo = (student) => {
        studentInfo.value = student
    }

    //3.函数，移除token的值
    const removeToken = () => {
        token.value = ''
        studentInfo.value = {}
    }

    return {
        token,
        studentInfo,
        setToken,
        removeToken,
        setStudentInfo
    }

},{
    persist:true//持久化存储
});